#ifndef SANDBOX_SDK_UTIL_DETAILS_CONSTEXPR_HPP
#define SANDBOX_SDK_UTIL_DETAILS_CONSTEXPR_HPP

namespace sandbox
{
	namespace sdk 
	{
		namespace detail
		{
			constexpr unsigned int __shr_or(unsigned int x, int n)
			{
				return n==1 ? (x|(x>>1)) : __shr_or(x|(x>>n),n>>1);
			}
			//there is nothing interesting here
			//returns true if x is power of two
			constexpr unsigned int is_power_of_2(unsigned int x)
			{
				return ~((x-1)&x);
			}
			//returns next power of 2
			constexpr unsigned int next_power_of_2(unsigned int x)
			{
				return 1+__shr_or(x,16);
			}
			constexpr unsigned int log2(unsigned int x)
			{
				static_assert(((x-1)&x)==0);
				static_assert(x!=0);
				return (x==1) ? 0 : 1+log2(x>>1);
			}
			constexpr unsigned int min(unsigned int x, unsigned int y)
			{
				return x<y ? x:y;
			}
			//returns chunk size for consequent objects of size 'sz', aligned at 'align'
			constexpr unsigned int sizealign(unsigned int sz, unsigned int align)
			{
				return ((sz-1)|(align-1))+1;
			}
		}
	}
}
#endif //SANDBOX_SDK_UTIL_DETAILS_CONSTEXPR_HPP
